package com.jml.咕泡.手写mybatisV1.demo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.mapping.Environment;

/**
 * Created by James on 2017-09-08.
 * From 咕泡学院出品
 * 老师咨询 QQ 2904270631
 */
public class Demo {

    {
        //configuration类对应mybatis-config.xml
        DataSource dataSource = null;
        Environment environment = new Environment("development", null, dataSource);
        Configuration configuration = new Configuration();
        configuration.setEnvironment(environment);
    }


    public static SqlSession getSqlSession() throws FileNotFoundException {
        String path = "F:\\jml-code\\idea_workspace\\constructor\\mybatis\\src\\main\\java\\com\\jml\\咕泡\\手写mybatisV1\\demo\\mybatis-config.xml";
        //配置文件
        InputStream configFile = new FileInputStream(path);
        //这个就把mybatis-config.xml和配置文件中Mapper加载了
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configFile);
        //加载配置文件得到SqlSessionFactory
         return sqlSessionFactory.openSession();
    }

    public static void main(String[] args) throws FileNotFoundException {
        getSqlSession();
        System.out.println("qq");
//        TestMapper testMapper = getSqlSession().getMapper(TestMapper.class);
//        Test test = testMapper.selectByPrimaryKey(1);
    }
}
